package com.sfzy.controller;

import com.github.pagehelper.PageInfo;
import com.sfzy.entity.PsyAss;
import com.sfzy.service.PsyAssService;
import com.sfzy.util.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @ClassName PsyAssController
 * @Description TODO
 * @Author niejiacan
 * @Date 2025年08月13日 19:59
 * @Version 1.0
 */
@RestController
@RequestMapping("PsyAss")
public class PsyAssController {
    @Autowired
    private PsyAssService psyAssService;

    @PostMapping
    public R addPsyAss(@RequestBody PsyAss psyAss){
        int i = psyAssService.addPsyAss(psyAss);
        if(i==0){
            return  R.fail();
        }
        return R.ok();
    }

    @PutMapping
    public R updatePsyAss(@RequestBody PsyAss psyAss){
        int i = psyAssService.updatePsyAss(psyAss);
        if(i==0){
            return R.fail();
        }
        return R.ok();
    }

    @DeleteMapping("{id}")
    public R deletePsyAss(@PathVariable("id") int id){
        int i = psyAssService.deletePsyAss(id);
        if(i==0){
            R.fail();
        }
        return R.ok();
    }

    @GetMapping("{id}")
    public R selectPsyAss(@PathVariable("id") int id){
        PsyAss psyAss = psyAssService.seletePsyAss(id);
        return  R.ok(psyAss);
    }

    @GetMapping("page2")
    public R pageName2(PsyAss psyAss,
                      @RequestParam(required = false,defaultValue = "1") int pageNum,
                      @RequestParam(required = false,defaultValue = "5") int pageSize){
        PageInfo<PsyAss> psyAssPageInfo = psyAssService.pageName2(psyAss,pageNum,pageSize);
        return R.ok(psyAssPageInfo);
    }



}
